package org.itboys.core.controller.web;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.core.entity.mysql.SundayInStoreOrder;
import org.itboys.core.service.mysql.web.SundayInStoreOrderService;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author：贾琦磊
 * @Date：2018/8/23
 * @Description：入库单接口
 */
@Controller
@RequestMapping("/sunday/web/order/store/in")
public class SundayInStoreOrderController extends BaseController {
    @Autowired
    private SundayInStoreOrderService inStoreOrderService;
    @RequestMapping("/index")
    public String index(HttpServletRequest request){
        return "/sunday/order/inStore/index";
    }

    @RequestMapping("/detail")
    public String input(HttpServletRequest request, Model model, @RequestParam("id") Long id){
        SundayInStoreOrder inStoreOrder = inStoreOrderService.findOne(id);
        model.addAttribute("order",inStoreOrder);
        return "/sunday/order/inStore/detail";
    }

    @RequestMapping("/select")
    public void select(HttpServletRequest request, HttpServletResponse response){
        try {
            PageResult<SundayInStoreOrder> result = inStoreOrderService.select(request);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }
}
